using HarmonyLib;
using RimWorld;
using System.Collections.Generic;
using Verse;
using Verse.AI;
using UnityEngine;
using System.Reflection.Emit;
using System.Linq;

namespace RimZombieGirl
{
    [HarmonyPatch(typeof(Thing), "Ingested")]
    public static class Thing_Ingested_Postfix
    {
        [HarmonyPostfix]
        public static void Postfix(Pawn ingester, float nutritionWanted, float __result)
        {
            // __result 摄入的营养值
            float nutritionGained = __result;
            
            // 基因处理
            for (int i = 0; i < ingester?.genes?.GenesListForReading.Count; i++)
            {
                GeneExt gene = ingester?.genes?.GenesListForReading[i] as GeneExt;
                if (gene != null)
                {
                    try
                    {
                        gene.Notify_IngestedNutrition(ingester, nutritionGained);
                    }
                    catch (System.Exception ex)
                    {
                        Log.Error("Error in GeneExt.Notify_IngestedNutrition(): " + ex);
                    }
                }
            }
        }
    }
}